home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-valcha.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  68 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                      S Y S T E M . V A L _ C H A R                       --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.7 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Val_Util; use System.Val_Util;
  27.  
  28. package body System.Val_Char is
  29.  
  30.    ---------------------
  31.    -- Value_Character --
  32.    ---------------------
  33.  
  34.    function Value_Character (Str : String) return Character is
  35.       F : Natural;
  36.       L : Natural;
  37.       S : String (Str'Range) := Str;
  38.  
  39.    begin
  40.       Normalize_String (S, F, L);
  41.  
  42.       --  Accept any single character enclosed in quotes
  43.  
  44.       if L - F = 2 and then S (F) = ''' and then S (L) = ''' then
  45.          return Character'Val (Character'Pos (S (F + 1)));
  46.  
  47.       --  Check control character cases
  48.  
  49.       else
  50.          for C in Character'Val (16#00#) .. Character'Val (16#1F#) loop
  51.             if S (F .. L) = Character'Image (C) then
  52.                return C;
  53.             end if;
  54.          end loop;
  55.  
  56.          for C in Character'Val (16#7F#) .. Character'Val (16#9F#) loop
  57.             if S (F .. L) = Character'Image (C) then
  58.                return C;
  59.             end if;
  60.          end loop;
  61.  
  62.          raise Constraint_Error;
  63.       end if;
  64.  
  65.    end Value_Character;
  66.  
  67. end System.Val_Char;
  68.